package io.summer.basis.excepts;

import io.summer.basis.api.ApiCode;
import io.summer.basis.enums.IEnumCode;

/**
 * generic exception.
 *
 * @author Moonlight
 */
public class AppException extends RuntimeException implements IEnumCode {
  private static final long serialVersionUID = 1L;

  private int code = ApiCode.INTERNAL_SERVER_ERROR.getCode();

  public AppException() {
    super(ApiCode.INTERNAL_SERVER_ERROR.getMessage());
  }

  public AppException(String message) {
    super(message);
  }

  public AppException(String message, Object... params) {
    super(String.format(message, params));
  }

  public AppException(int errorCode, String message) {
    super(message);
    code = errorCode;
  }

  public AppException(IEnumCode apiCode) {
    super(apiCode.getMessage());
    this.code = apiCode.getCode();
  }

  public AppException(String message, Throwable cause) {
    super(message, cause);
  }

  public AppException(Throwable cause) {
    super(cause);
  }

  @Override
  public int getCode() {
    return code;
  }
}
